import Taro from '@tarojs/taro'
import { baseUrl as BASE_URL } from './url'
import store from '../store/store'

const httpApi = (url, params,loading, method, header ) => {
    console.log('======================111')
    if (loading) {
        Taro.showLoading({
            title: '正在加载'
        })
    }
    console.log('======================222',BASE_URL(url))
    return new Promise((resolve, reject) => {
        let { appletsToken, loginToken, accessToken} = store
        Taro.request({
            url: BASE_URL(url),
            header: {
                ...header,
                'applets-token':'',
                'login-token': '',
                'access-token': '', // :'ded7016c7ec230776313b1c8b4ab077a',
                'content-type': 'application/json',
            },
            method: method || 'POST',
            data: params || {},
            success: res => {
                Taro.hideLoading()
                resolve(res.data)
            },
            fail: error => {
                Taro.hideLoading()
                Taro.showToast({
                    title: '请求失败',
                    icon: 'none'
                })
                reject(error)
            }
        })
    })
}

export { httpApi }
